﻿using System.Linq;
using System.Web.Mvc;
using Icms.Core;
using Icms.Core.Model;
using Icms.Core.Service;
using Icms.WebUI.Builder;
using Icms.WebUI.Dto;
using Omu.Awesome.Mvc;

namespace Icms.WebUI.Controllers
{
    [Authorize(Roles="admin")]
    public class CourtController : Cruder<Court, CourtInput>
    {
        public CourtController(ICrudService<Court> s, IMapper<Court, CourtInput> v)
            : base(s, v)
        {
        }

        public virtual ActionResult Search(string search, int page = 1, int ps = 5)
        {
            var src = s.Where(o => o.Title.Contains(search));
            var rows = this.RenderView("rows", src.OrderBy(u => u.Id).Pag(page, ps));

            return Json(new { rows, more = src.Count() > page * ps });
        }
    }
}